
package jweslley.ContestVolumes.VolumeCIII;

import java.util.Scanner;

import jweslley.Problem;
import jweslley.Problem.Status;

/**
 * http://icpcres.ecs.baylor.edu/onlinejudge/external/103/10300.html
 *
 * @author  Jonhnny Weslley
 * @version 1.00, 21/10/2008
 */
@Problem(Status.Accepted)
public class EcologicalPremium {

	public static void main(String[] args) {
		StringBuilder out = new StringBuilder();
		Scanner in = new Scanner(System.in);
		int n, f, area, animals, level, sum;
		n = in.nextInt();
		while (n --> 0) {
			sum = 0;
			f = in.nextInt();
			while (f --> 0) {
				area = in.nextInt();
				animals = in.nextInt();
				level = in.nextInt();
				sum += area * level;
			}
			out.append(sum).append('\n');
		}
		System.out.print(out);
	}

}
